#include "queue_buffer_cfg.h"
#include "queue_buffer.h"
#include <stdio.h>	/* printf */
#include <string.h>	/* memset */

int main()
{
	qbuf_t *ptmp, *psend, *prcv;

	qbuf_groups_cfg();

	/* 用作临时内存 */
	ptmp = qbuf_alloc(QBUF_GROUP_TMPBUF);
	if (!ptmp) {
		printf("alloc memory error\n");
		return -1;
	}

	memset(ptmp->addr, 'U', ptmp->size);
	ptmp->addr[ptmp->size - 1] = '\0';
	ptmp->len = ptmp->size;
	printf("got memory and write data %d 'U': %s\n", ptmp->len - 1, ptmp->addr);
	qbuf_free(ptmp);

	/* 用作模块消息缓存 */
	psend = qbuf_alloc(QBUF_GROUP_DATBUF);
	if (!psend) {
		printf("alloc memory error\n");
		return -1;
	}
	memset(psend->addr, 'V', psend->size);
	psend->addr[psend->size - 1] = '\0';
	psend->len = psend->size;
	printf("write data %d 'V': %s, and send\n", psend->len - 1, psend->addr);

	qbuf_put(psend);	/* 发送 */
	
	prcv = qbuf_get(QBUF_GROUP_DATBUF);	/* 查询并接收 */
	if (!prcv) {
		printf("get error\n");
		return -1;
	}
	printf("receive and got %d data : %s\n", prcv->len - 1, prcv->addr);

	return 0;
}